/**
 * 步骤无人时，调整责任人
 */
 import { useForm } from "../../framework/common/context/metadata-context";
 import {getQuery} from "../../framework/common/utils"
 import "./approveStepReadonly.css"
import Operations from "./Operations";
import React, { useEffect, useRef, useState } from "react";
import clsx from "clsx";
import { Tooltip , Input, Radio, Space, Checkbox, Spin } from "antd";
import get from "lodash/get";
import message from "../../framework/common/utils/message";
import request from "../../framework/common/utils/request";
import getInitiateFormData from "../../framework/common/utils/getInitiateFormData";
import BranchChoose from "./BranchChoose1";
import {v4 as uuid} from 'uuid'
import { InjectProvider, useInject } from "../../framework/common/context/inject-context";
import TemporaryStep from "./TemporaryStep1";//临时步骤模板
import { useUpdate } from "ahooks";
import SelectAuditors from "../SelectAuditors/SelectAuditors";

export default function({
    step = {},//当前步骤
    tplData = {},
    params = {},
    ind = null,
    actual_steps=[],//实际步骤
    parentUpdater=null,
    urlPrefix= null
}){
    let updater = useUpdate();

    //更新父组件信息
    function updateParentUpdater(){
        parentUpdater && parentUpdater()
    }

    let p_step = actual_steps.find(function(s) {
        return s.id == step.id;
    });//actual_steps步骤内的当前步骤，需要同时修改

    let multiSelect = step.stepAttrs && step.stepAttrs.multi_type == "Multi";

    //步骤责任人必填状态
    const nodeStatusRef = useRef(null);
    let nodeStatus = nodeStatusRef.current;
    
    return <SelectAuditors
        data-path={ind}
        CurUserGUID={tplData.CurUserGUID} 
        placeholder={"请选择责任人"}
        package_id={tplData.package_id}
        CurUserDepartmentGUID={tplData.CurUserDepartmentGUID} 
        urlPrefix={urlPrefix}
        multiSelect={multiSelect}
        status={nodeStatus}
        onChange={(data)=>{

            //把责任人回写到步骤信息内
            step.nodes = data;
            if (step.nodes.length) {
                step.nodes.map(function(item, i) {
                    item.Checked = true;
                });
            }
            step.is_user_reset_activity = 1;
            p_step.nodes = data;
            p_step.is_user_reset_activity = 1;

            //校验步骤选人必填
            if (step.nodes.length > 0) {
                nodeStatusRef.current = "";//取消必填校验
            } else {
                nodeStatusRef.current = "error";//增加必填校验
            }

            updater();
            updateParentUpdater();
        }}
        title={"责任人"}
    ></SelectAuditors>
}